# -------------- Configuration of the Radium Gui targets and definitions -------
# Setup Gui and check for dependencies

# TODO : verify if this is needed
if(Gui_FOUND AND NOT TARGET Gui)
    set(Configure_Gui ON)
    # verify dependencies
    if(NOT Engine_FOUND)
        if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../Engine/RadiumEngineConfig.cmake")
            set(Engine_FOUND TRUE)
            include(${CMAKE_CURRENT_LIST_DIR}/../Engine/RadiumEngineConfig.cmake)
        else()
            set(Radium_FOUND False)
            set(Radium_NOT_FOUND_MESSAGE "Radium::Gui: dependency Engine not found")
            set(Configure_Gui OFF)
        endif()
    endif()
    if(Configure_Gui AND NOT IO_FOUND)
        if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../IO/RadiumIOConfig.cmake")
            set(IO_FOUND TRUE)
            include(${CMAKE_CURRENT_LIST_DIR}/../IO/RadiumIOConfig.cmake)
        else()
            set(Radium_FOUND False)
            set(Radium_NOT_FOUND_MESSAGE "Radium::Gui: dependency IO not found")
            set(Configure_Gui OFF)
        endif()
    endif()
endif()

if(Configure_Gui)
    include(${CMAKE_CURRENT_LIST_DIR}/../QtFunctions.cmake)
    check_and_set_qt_version("@QT_DEFAULT_MAJOR_VERSION@")
    find_qt_dependency(COMPONENTS Core Widgets OpenGL Xml REQUIRED)

    # Theses paths reflect the paths founds in RadiumEngine/external/Gui/package
    set(_BaseExternalDir_ "${CMAKE_CURRENT_LIST_DIR}/../../../../")
    if("@PowerSlider_DIR@" STREQUAL "")
        set(PowerSlider_DIR "${_BaseExternalDir_}/@PowerSlider_sub_DIR@")
    else()
        set(PowerSlider_DIR "@PowerSlider_DIR@")
    endif()
    find_dependency(PowerSlider REQUIRED NO_DEFAULT_PATH)

    if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../PluginBase/RadiumPluginBaseConfig.cmake")
        set(PluginBase_FOUND TRUE)
        include(${CMAKE_CURRENT_LIST_DIR}/../PluginBase/RadiumPluginBaseConfig.cmake)
    endif()

    if(MSVC OR MSVC_IDE OR MINGW)
        get_target_property(QTLIB Qt::Core INTERFACE_LINK_LIBRARIES)
        add_imported_dir(FROM ${QTLIB} TO RadiumExternalDlls_location)
        add_imported_dir(FROM PowerSlider::PowerSlider TO RadiumExternalDlls_location)
    endif()
    include("${CMAKE_CURRENT_LIST_DIR}/GuiTargets.cmake")
endif()
